package main

import "fmt"

func main() {

	m := map[int]string{}
	m[1] = "one"
	m[2] = "two"
	m[3] = "three"
	m[4] = "four"
	m[5] = "five"
	m[6] = "six"

	for k, v := range m {
		fmt.Printf("key: %d, value:%s\n", k, v)
	}

	m1 := make(map[string]string)
	m1["name"] = "alex"
	m1["age"] = "16"
	m1["name"] = "alen" // 会覆盖掉

	for k, v := range m1 {
		fmt.Printf("key: %s, value:%s\n", k, v)
	}

	m2 := map[string]string{
		"address": "上海",
		"data":    "2025-6-20",
	}

	for k, v := range m2 {
		fmt.Printf("key: %s, value:%s\n", k, v)
	}

	v, ok := m2["asldkjlkasdf"]
	if ok {
		fmt.Printf("the v: %s\n", v)
	} else {
		fmt.Printf("the ok: %v\n ", ok)
	}

	MapPrint()
}

func MapPrint() {
	m := map[string]string{}

	// add
	m["name"] = "alex"
	m["age"] = "2025"
	m["address"] = "BeiJin"
	for k, v := range m {
		fmt.Printf("The key: %s, the value: %s\n", k, v)
	}

	// check
	if v, ok := m["aslkjdfad"]; ok {
		fmt.Printf("the v: %s\n", v)
	} else {
		fmt.Printf("the ok: %v\n", ok)
	}

	// modify
	m["address"] = "ShangHai"
	fmt.Printf("after modify\n")
	for k, v := range m {
		fmt.Printf("The key: %s, the value: %s\n", k, v)
	}

	// Delete
	delete(m, "address")
	fmt.Printf("after delete\n")
	for k, v := range m {
		fmt.Printf("The key: %s, the value: %s\n", k, v)
	}

}
